#!/bin/sh
# Transcode FLACs to Opus in bulk, retaining directory hierarchy.

# Specify the desired bitrate. See
# https://wiki.xiph.org/Opus_Recommended_Settings for more info.
bit=128

find ./ -type f -iname "*.flac" | while read -r i; do
  dest="${i#./}"
  dest="opus/${dest%/*}"
  file="${i##*/}"
  [ -d "$dest" ] || mkdir -p "$dest"
  opusenc --bitrate "$bit" "$i" "${dest}/${file%.flac}.opus"
done
